package com.chentf.rabbitmq.workquene01;

import com.chentf.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 工作队列-生产者生成消息
 */
public class Provider {

    public static void main(String[] args) throws IOException {
        //工具类,获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取通道对象
        Channel channel = connection.createChannel();
        //通过通道声明队列
        channel.queueDeclare("work",true,false,false,null);
        for (int i = 0; i < 20; i++) {
            //生成消息
            channel.basicPublish("","work",null,(i + "_"+"hello work quene").getBytes(StandardCharsets.UTF_8));
        }
        //关闭资源
        RabbitMQUtils.closeConnectionAndChanel(channel,connection);
    }
}
